load("//bazel:canisters.bzl", "rust_canister")
load("//bazel:defs.bzl", "rust_ic_bench", "rust_ic_test_suite")

package(default_visibility = ["//visibility:public"])

DEPENDENCIES = [
    # Keep sorted.
    "//rs/rust_canisters/dfn_core",
    "//rs/rust_canisters/dfn_json",
    "//rs/rust_canisters/on_wire",
    "@crate_index//:candid",
    "@crate_index//:ic-cdk",
    "@crate_index//:rand",
    "@crate_index//:rand_pcg",
    "@crate_index//:serde",
    "@crate_index//:serde_json",
]

MACRO_DEPENDENCIES = []

DEV_DEPENDENCIES = [
    # Keep sorted.
    "//packages/ic-error-types",
    "//rs/canister_client/sender",
    "//rs/rust_canisters/canister_test",
    "//rs/rust_canisters/dfn_candid",
    "//rs/test_utilities",
    "//rs/test_utilities/identity",
    "//rs/types/management_canister_types",
    "//rs/types/types",
    "@crate_index//:assert_matches",
    "@crate_index//:criterion",
]

MACRO_DEV_DEPENDENCIES = []

ALIASES = {}

rust_ic_bench(
    name = "json_bench",
    testonly = True,
    srcs = ["benches/json.rs"],
    crate_root = "benches/json.rs",
    data = [
        ":json",
    ],
    env = {
        "JSON_WASM_PATH": "$(rootpath :json)",
        "CARGO_MANIFEST_DIR": "rs/rust_canisters/tests/",
    },
    proc_macro_deps = MACRO_DEPENDENCIES,
    deps = DEPENDENCIES + DEV_DEPENDENCIES,
)

rust_canister(
    name = "json",
    srcs = ["src/json.rs"],
    aliases = ALIASES,
    proc_macro_deps = MACRO_DEPENDENCIES,
    service_file = ":test/empty.did",
    deps = DEPENDENCIES,
)

rust_canister(
    name = "inter_canister_error_handling",
    srcs = ["src/inter_canister_error_handling.rs"],
    aliases = ALIASES,
    proc_macro_deps = MACRO_DEPENDENCIES,
    service_file = ":test/empty.did",
    deps = DEPENDENCIES,
)

rust_canister(
    name = "nan_canonicalized",
    srcs = ["src/nan_canonicalized.rs"],
    aliases = ALIASES,
    proc_macro_deps = MACRO_DEPENDENCIES,
    service_file = ":test/empty.did",
    deps = DEPENDENCIES,
)

rust_canister(
    name = "stable",
    srcs = ["src/stable.rs"],
    aliases = ALIASES,
    proc_macro_deps = MACRO_DEPENDENCIES,
    service_file = ":test/empty.did",
    deps = DEPENDENCIES,
)

rust_canister(
    name = "time",
    srcs = ["src/time.rs"],
    aliases = ALIASES,
    proc_macro_deps = MACRO_DEPENDENCIES,
    service_file = ":test/empty.did",
    deps = DEPENDENCIES,
)

rust_canister(
    name = "panics",
    srcs = ["src/panics.rs"],
    aliases = ALIASES,
    proc_macro_deps = MACRO_DEPENDENCIES,
    service_file = ":test/empty.did",
    deps = DEPENDENCIES,
)

rust_ic_test_suite(
    name = "tests_test",
    srcs = glob(["test/**/*.rs"]),
    aliases = ALIASES,
    data = [
        ":inter_canister_error_handling",
        ":json",
        ":nan_canonicalized",
        ":panics",
        ":stable",
        ":time",
        "//rs/universal_canister/impl:universal_canister.wasm.gz",
    ],
    env = {
        "NAN_CANONICALIZED_WASM_PATH": "$(rootpath :nan_canonicalized)",
        "STABLE_WASM_PATH": "$(rootpath :stable)",
        "TIME_WASM_PATH": "$(rootpath :time)",
        "PANICS_WASM_PATH": "$(rootpath :panics)",
        "JSON_WASM_PATH": "$(rootpath :json)",
        "CARGO_MANIFEST_DIR": "rs/rust_canisters/tests",
        "INTER_CANISTER_ERROR_HANDLING_WASM_PATH": "$(rootpath :inter_canister_error_handling)",
        "UNIVERSAL_CANISTER_WASM_PATH": "$(rootpath //rs/universal_canister/impl:universal_canister.wasm.gz)",
    },
    proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
    deps = DEPENDENCIES + DEV_DEPENDENCIES,
)
